{% extends 'blog/base.html' %}

{% block content %}
    <div class="post">
        {% if post.published_date %}
            <div class="date">
                {{ post.published_date }}
            </div>
            <h1>{{ post.title }}</h1>
            <p>{{ post.text|linebreaksbr }}</p>
            {% if user.is_authenticated %}
                <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a>
                <a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
            {% endif %}
        {% else %}
            <h2>Error: record with id={{ post.id }} is not published yet.</h2>
            {% if user.is_authenticated %}
                <p><a href="{% url 'post_publish' pk=post.pk %}">Publish this post</a> or return to <a href="{% url 'post_list' %}"> posts list</a>?</p>
                <p>You can also <a href="{% url 'post_remove' pk=post.pk %}">remove this post</a>.</p>
            {% else %}
                <p>Return to <a href="{% url 'post_list' %}"> posts list</a>?</p>
            {% endif %}
        {% endif %}
    </div>
    <hr>
    <a class="btn btn-default btn-comment" href="{% url 'add_comment_to_post' pk=post.pk %}">Add comment</a>
    {% for comment in post.comments.all %}
        {% if user.is_authenticated or comment.approved_comment %}
            <div class="comment">
                <div class="date">{{ comment.created_date }}</div>
                {% if not comment.approved_comment %}
                    <a class="btn btn-default" href="{% url 'comment_remove' pk=comment.pk %}"><span class="glyphicon glyphicon-remove"></span></a>
                    <a class="btn btn-default" href="{% url 'comment_approve' pk=comment.pk %}"><span class="glyphicon glyphicon-ok"></span></a>
                {% endif %}
                <strong>{{ comment.author }}</strong>
                <p>{{ comment.text }}</p>
            </div>
        {% endif %}
    {% empty %}
        <p>No comments here yet :(</p>
    {% endfor %}
{% endblock %}